package demo4;

class Food {
}

class Fruit extends Food {

}

class Apple extends Fruit {

}

class Banana extends Fruit {

}

class Plate<T> {
    private T plate;

    public T getPlate() {
        return plate;
    }

    public void setPlate(T plate) {
        this.plate = plate;
    }
}

public class Test {
    // 通配符的下界，可以接收的是Fruit和他的父类
    public static void func(Plate<? super Fruit> temp) {
        // 可以修改但不能get
        temp.setPlate(new Apple());
        temp.setPlate(new Banana());

        //Fruit fruit = (Fruit) temp.getPlate(); // 不能接收，这里无法确定是哪个父类
    }

    public static void main(String[] args) {
        Plate<Food> plate1 = new Plate<>();
        Plate<Fruit> plate2 = new Plate<>();
        func(plate1);
        func(plate2);
    }
}

